package com.android.plc.ui.control;

import android.content.Context;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageButton;

import com.android.plc.CONST.COMMAND;
import com.android.plc.CONST;
import com.android.plc.R;

public class BoxControl extends TVPlayControl implements OnClickListener
{
	private static final int OFFSET_3 = 3;
	private static final int OFFSET_4 = 4;
	private static final int OFFSET_5 = 5;
	private static final int OFFSET_6 = 6;

	private Button mBackBtn;
	private Button mMuteBtn;
	private Button mAVBtn;
	private Button mConfirmBtn;
	private Button mTVPlusBtn;
	private Button mTVMinsBtn;
	private ImageButton mTVOnBtn;
	private ImageButton mTVOffBtn;

	public BoxControl(Context context, ViewGroup view, int res_id)
	{
		super(context, view, res_id);
	}

	public BoxControl(Context context, ViewGroup view)
	{
		super(context, view, R.layout.control_stb);
	}

	@Override
	public void initView(ViewGroup view)
	{
		super.initView(view);

		mBackBtn = (Button) view.findViewById(R.id.btn_stb_back);
		mConfirmBtn = (Button) view.findViewById(R.id.btn_stb_confirm);
		mAVBtn = (Button) view.findViewById(R.id.btn_stb_av);
		mMuteBtn = (Button) view.findViewById(R.id.btn_stb_mute);

		mTVPlusBtn = (Button) view.findViewById(R.id.btn_tv_plus);
		mTVMinsBtn = (Button) view.findViewById(R.id.btn_tv_mins);
		mTVOnBtn = (ImageButton) view.findViewById(R.id.btn_tv_on);
		mTVOffBtn = (ImageButton) view.findViewById(R.id.btn_tv_off);

		mBackBtn.setOnClickListener(this);
		mConfirmBtn.setOnClickListener(this);
		mAVBtn.setOnClickListener(this);
		mMuteBtn.setOnClickListener(this);

		mTVPlusBtn.setOnClickListener(this);
		mTVMinsBtn.setOnClickListener(this);

		mTVOnBtn.setOnClickListener(this);
		mTVOffBtn.setOnClickListener(this);
	}

	public void onClick(View v)
	{
		switch (v.getId())
		{
		case R.id.btn_stb_back:
			sendCommand(OFFSET_5, COMMAND.ON, CONST.DEF_DATA, 0);
			break;
		case R.id.btn_stb_confirm:
			sendCommand(OFFSET_5, COMMAND.OFF, 0, 0);
			break;
		case R.id.btn_stb_av:
			sendCommand(OFFSET_6, COMMAND.ON, CONST.DEF_DATA, 0);
			break;
		case R.id.btn_stb_mute:
			sendCommand(OFFSET_6, COMMAND.OFF, 0, 0);
			break;
		case R.id.btn_tv_plus:
			sendCommand(OFFSET_2, COMMAND.ON, CONST.DEF_DATA, 0);
			break;
		case R.id.btn_tv_mins:
			sendCommand(OFFSET_2, COMMAND.OFF, 0, 0);
			break;
		case R.id.btn_tv_on:
			sendCommand(OFFSET_1, COMMAND.ON, CONST.DEF_DATA, 0);
			break;
		case R.id.btn_tv_off:
			sendCommand(OFFSET_1, COMMAND.OFF, 0, 0);
			break;
		case R.id.btn_ch_plus:
			sendCommand(OFFSET_3, COMMAND.ON, CONST.DEF_DATA, 0);
			break;
		case R.id.btn_ch_mins:
			sendCommand(OFFSET_3, COMMAND.OFF, 0, 0);
			break;
		case R.id.btn_vol_plus:
			sendCommand(OFFSET_4, COMMAND.ON, CONST.DEF_DATA, 0);
			break;
		case R.id.btn_vol_mins:
			sendCommand(OFFSET_4, COMMAND.OFF, 0, 0);
			break;
		default:
			super.onClick(v);
			break;
		}

	}
}
